package com.cap.bts.framework.location.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.cap.bts.framework.common.exception.AppException;
import com.cap.bts.framework.location.domain.LocationInfo;
import com.cap.bts.framework.location.service.LocationInfoService;

/**
 * @author: huiwu
 * @data：Oct 14, 2014
 * 
 */
@Controller
@RequestMapping("/dm/locationinfo") //根路径
public class LocationInfoRestController {
    @Autowired
    private LocationInfoService locationInfoService;
    
    @RequestMapping(value="/save",method=RequestMethod.POST)
    public String saveLocationInfo(LocationInfo lf) throws AppException{
        locationInfoService.addLocationInfo(lf);
        return "redirecct:/dm/locationinfo/findAll";
    }
    
    @RequestMapping(value="/findAll")
    public String findAllLocationInfo(Model model,HttpServletRequest request) throws AppException {
       List<LocationInfo> locationinfolist = locationInfoService.getAllLocationInfo();
        model.addAttribute("locationInfos",locationinfolist);
        //TODO  add pager 
        return "locationInfoList";
    }
    
    @RequestMapping(value="/addLocationUI")
    public String addLocationInfoUI(Model model){
        return "addLocationInfo";
    }
    
    @RequestMapping(value="/delete")
    public String deleteLocationInfo(Long id) throws AppException{
        locationInfoService.deleteLocationInfo(id);
        return "redirecct:/dm/locationinfo/findAll";
    }
    
    @RequestMapping(value="/editLocationInfoUI")
    public String editLocationInfoUI(Long id, Model model) throws AppException{
        LocationInfo lf = locationInfoService.getLocationInfoById(id);
        model.addAttribute("lf",lf);
        return "editLocationInfo";
    }
    
    @RequestMapping(value="/update")
    public String updateLocationInfo(LocationInfo lf) throws AppException{
        locationInfoService.updateLocationInfo(lf);
        return "redirecct:/dm/locationinfo/findAll";
    }
}
